#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H

#include <QGraphicsView>
#include "APnMApp.h"
#include "gactiveelement.h"
#include "tokensinput.h"
class APnMScene;

class APnMView : public QGraphicsView
{
	Q_OBJECT

public:
	APnMView(QWidget *parent);
	~APnMView();

	void newFile();
	bool loadFile(const QString &fileName);
	bool save();
	bool saveAs();
	bool saveFile(const QString &fileName);
	bool print();
	QString userFriendlyCurrentFile();
	QString currentFile() { return curFile; }

	bool hasSelection();

	bool tokenMode() { return mTokenMode; }
	void setTokenMode(bool mode) { mTokenMode = mode; }
	bool runMode() { return mRunMode; }

	bool upload();
	bool terminate();

	//void addTextItem();

public slots:
	void selectionChanged();
	void cut();
	void copy();
	void paste();
	void del();

	void addLink(Link* newLink);

	void compositeUp();
	void compositeDown();

signals:
	void copyAvailable(bool yes);
	void openFile(const QString & noSuffix);

protected:
	//Drag and Drop
	void dragEnterEvent ( QDragEnterEvent * event );
	void dragMoveEvent ( QDragMoveEvent * event );
	void dropEvent ( QDropEvent * event );
	
	void keyPressEvent ( QKeyEvent * event ) ;
	void contextMenuEvent ( QContextMenuEvent * event ); 

	//token Mode
	void mousePressEvent ( QMouseEvent * event );

	//related to save the corresponding application
	void closeEvent(QCloseEvent *event);

private:
	void setElementName(GElement* ele);
	void flipPortNameVisible(GActiveElement* activeEle);
	void showPortInfo(GActiveElement* activeEle);
	void showFunction(GElement* ele);
	void showSemantics(GElement* ele);
	void showPatterns(GElement* ele);
	void showExamples(GElement* ele);
	void viewList(const QStringList& data, const QString& name);
	void showDocument(GElement* ele);

private:	
	//control information on the current Scientific Workflow Application 
	bool maybeSave();
	void setCurrentFile(const QString &fileName);
	QString strippedName(const QString &fullFileName);

	//Model(MVC pattern) of the Scientific Workflow Application 
	APnMScene *mScene;
	APnMApp mApp;

	QMap<QString, TokensInput*> mTokenEditors; //manipulate token: view, add, delete,... 

	QString curFile;
	bool isUntitled;

	bool mTokenMode;
	bool mRunMode;
	//Server
	QString mHost;
	quint16 mPort;
};

#endif // GRAPHICSVIEW_H
